﻿using PersistentObject.Common;
using PersistentObject.Common.Criteria;
using PersistentObject.Common.Schema;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PersistentObject.Oracle11GR2
{
    public class CriteriaCreatorForOracle : BaseCriteriaCreator
    {
        public CriteriaCreatorForOracle(Table mainTable, BaseDialect dialect)
            :base(mainTable, dialect)
        {
        }
        public override string GetCriteriaClause(BinaryCriteria criteria)
        {
            switch (criteria.Comparison)
            {
                case BinaryComparison.Like:
                case BinaryComparison.NotLike:
                    return string.Format("({0} {1} {2})",
                        GetOperandClause(criteria.Left),
                        GetComparisonScript(criteria.Comparison),
                        "'%' || " + GetOperandClause(criteria.Right) + " || '%'"
                        );
                case BinaryComparison.BeginWith:
                    return string.Format("({0} {1} {2})",
                        GetOperandClause(criteria.Left),
                        GetComparisonScript(criteria.Comparison),
                        GetOperandClause(criteria.Right) + " || '%'"
                        );
                case BinaryComparison.EndWith:
                    return string.Format("({0} {1} {2})",
                        GetOperandClause(criteria.Left),
                        GetComparisonScript(criteria.Comparison),
                        "'%' || " + GetOperandClause(criteria.Right)
                        );
                default:
                    return string.Format("({0} {1} {2})",
                        GetOperandClause(criteria.Left),
                        GetComparisonScript(criteria.Comparison),
                        GetOperandClause(criteria.Right)
                        );
            }
        }
    }
}
